<template>
	<view class="seed p-20">
		<view class="number bold m-b-10">
			{{user.seed}}
		</view>
		<view class="f-xxs m-b-30">创世种子</view>
		<u--image src="../../static/img/seed.png" width="100%" height="264"></u--image>
		<swiper class="swiper" :indicator-dots="false">
			<swiper-item>
				<view class="swiper-item border-box">
					<view class="f-base m-b-20 flex-no-horizontal">
						<u-icon name="info-circle" size="16" class="m-r-5"></u-icon>
						<view class="f-base bold">创世种子</view>
					</view>
					<view class="f-base">
						「艾草种植」游戏中可流转游戏道具，分为创世种子与普通种子。创世种子通过预约活动获得，普通种子由创世种子繁育获得。用户购买及种植两种种子将获得对应福利。
					</view>
				</view>
			</swiper-item>
			<swiper-item>
				<view class="swiper-item border-box">
					<view class="title flex-no-horizontal m-b-20">
						<text class="grey f-xs" :class="active === 1 ? 'active' : ''"
						@click="change(1)">收</text>
						<text class="line"></text>
						<text class="grey f-xs" :class="active === 2 ? 'active' : ''"
						@click="change(2)">支</text>
					</view>
					<view class="record" v-if="list.length">
						<view class="record-item m-b-20" v-for="(item,index) in list" :key="index">
							<view class="flex-no-horizontal record-item-title m-b-10">
								<view class="f-base">{{item.state}}</view>
								<view class="bold f-17">{{ item.type === 1 ? "+" : "-" }}{{ item.quantity }}</view>
							</view>
							<view class="grey f-xxs">{{item.time | date('yyyy-mm-dd hh:MM')}}</view>
						</view>
					</view>
					<view class="empty" v-else>
						暂无记录~
					</view>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import {
		seedRecord
	} from '../../api/collection.js'
	import {
		mapState
	} from 'vuex'
	export default {
		data () {
			return {
				list: [],
				active: 1, // 1收 2支
			}
		},
		computed: {
			...mapState({
				user: state => state.userInfo
			})
		},
		onLoad() {
			this.getRecordList()
		},
		methods: {
			async getRecordList () {
				try{
					const res = await seedRecord({
						type: this.active
					})
					this.list = res.data.storelog
				} catch(e) {
					uni.showToast({
						title: e.data || e.message,
						icon: 'none'
					})
					console.log(e)
				}
			},
			change (index) {
				this.active = index
				this.getRecordList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.seed {
		min-height: 100%;
		background-color: #FFFFFF;
		.number {
			font-size: 43px;
		}
		.swiper{
			margin-top: 40rpx;
			height: 550rpx;
			.swiper-item{
				height: 100%;
				background: url(../../static/img/seed-down.png) no-repeat;
				background-size: 100% 100%;
				border-radius: 40rpx;
				overflow: scroll;
				padding: 60rpx;
				background-color: #E1EBF3;
				.record-item{
					.record-item-title{
						justify-content: space-between;
					}
				}
				.empty{
					display: flex;
					align-items: center;
					justify-content: center;
					height: 80%;
					font-size: 14px;
				}
				.active{
					font-size: 19px;
					color: #000000;
					font-weight: 700;
				}
				
				.line{
					width: 2px;
					height: 38rpx;
					background: #c9c9c9;
					margin: 0 10px;
					display: inline-block;
				}
			}
		}
	}
</style>
